package com.jeff.tianti.cms.dao;

import com.jeff.tianti.common.dao.CustomBaseSqlDaoImpl;
import com.jeff.tianti.common.entity.PageModel;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.jeff.tianti.cms.entity.TalentPool;
import com.jeff.tianti.cms.dto.TalentPoolQueryDTO;
import org.apache.commons.lang3.StringUtils;

/**
 * @author xujianfang
 * @desc TalentPoolDaoImpl��
 * @date 2019-07-09
 */

public class TalentPoolDaoImpl extends CustomBaseSqlDaoImpl implements TalentPoolDaoCustom {

    public PageModel<TalentPool> queryTalentPoolPage(TalentPoolQueryDTO talentPoolQueryDTO) {
        Map<String, Object> map = new HashMap<String, Object>();
        StringBuilder hql = new StringBuilder();
        hql.append("select t from TalentPool t where 1=1 ");
        if (talentPoolQueryDTO != null) {
            String talentType = talentPoolQueryDTO.getTalentType();
            if (StringUtils.isNotBlank(talentType) && !"-1".equals(talentType)) {
                hql.append(" and t.talentType = :talentType ");
                map.put("talentType", talentType);
            }
            String deleteFlag = talentPoolQueryDTO.getDeleteFlag();
            if (StringUtils.isNotBlank(deleteFlag)) {
                hql.append(" and t.deleteFlag = :deleteFlag ");
                map.put("deleteFlag", deleteFlag);
            }
            String type = talentPoolQueryDTO.getType();
            if (StringUtils.isNotBlank(type) && !"-1".equals(type)) {
                hql.append(" and t.type = :type ");
                map.put("type", type);
            }
        }
        hql.append(" order by t.sort desc ");
        return this.queryForPageWithParams(hql.toString(), map, talentPoolQueryDTO.getCurrentPage(), talentPoolQueryDTO.getPageSize());
    }

    public List<TalentPool> queryTalentPoolList(TalentPoolQueryDTO talentPoolQueryDTO) {
        Map<String, Object> map = new HashMap<String, Object>();
        StringBuilder hql = new StringBuilder();
        hql.append("select t from TalentPool t where t.deleteFlag = 0 order by t.sort desc");
        return this.queryByMapParams(hql.toString(), map);
    }


}